//
//  NYDetailContentActionCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/10.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYDetailContentActionCell.h"
@interface NYDetailContentActionCell ()
@property(nonatomic, strong) QMUIButton *addClassBtn;
@property(nonatomic, strong) QMUIButton *completeClassBtn;
@end
@implementation NYDetailContentActionCell
+ (CGFloat)heightForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath tableView:(UITableView *)tableView
{
        return __WGHeight(51);
}
- (BOOL)shouldUpdateCellWithObject:(NICellObject *)object
{
        self.detailModel = object.userInfo;
        return YES;
}
- (void)setDetailModel:(NYCourseModel *)detailModel
{
        _detailModel = detailModel;
        [self updateContent];
}
- (void)updateContent
{
        self.addClassBtn.enabled = (self.detailModel.join_my_course == 1);
        self.completeClassBtn.selected = (self.detailModel.currentPlayModel.is_learn == 2);
}
- (void)setupView
{
        [super setupView];
        UIStackView *stackView = [[UIStackView alloc] initWithArrangedSubviews:@[self.addClassBtn,self.completeClassBtn]];
        stackView.axis = UILayoutConstraintAxisHorizontal;
        stackView.distribution = UIStackViewDistributionFillEqually;
        stackView.alignment = UIStackViewAlignmentFill;
        stackView.spacing = 0;
        UIView *lineView = [[UIView alloc] init];
        lineView.backgroundColor = UIColorHex(0xDDDDDD);
        
        [self.contentView addSubview:stackView];
        [self.contentView addSubview:lineView];
        
        [stackView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.contentView).offset(__WGWidth(15));
                make.bottom.equalTo(self.contentView).offset(-__WGHeight(15));
                make.top.equalTo(self.contentView).offset(__WGHeight(15));
                make.right.equalTo(self.contentView).offset(-__WGWidth(15));
        }];
        [lineView mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(stackView);
                make.width.mas_equalTo(__WGWidth(1));
                make.height.mas_equalTo(__WGHeight(30));
        }];
        @weakify(self);
        [self.addClassBtn jk_addActionHandler:^(NSInteger tag) {
                @strongify(self);
                if (self.actionBlock) {
                        self.actionBlock(NYDetailContentActionTypeAddToMyClasses, self.detailModel);
                }
        }];
        [self.completeClassBtn jk_addActionHandler:^(NSInteger tag) {
                @strongify(self);
                if (self.actionBlock) {
                        self.actionBlock(NYDetailContentActionTypeCompleteClasses, self.detailModel);
                }
        }];
}
- (QMUIButton *)addClassBtn
{
        if ( _addClassBtn == nil )
        {
                _addClassBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImage jia_ru_ke_cheng] title:@"加入我的课程"];
                [_addClassBtn setTitleColor:UIColorHex(0x333333) forState:(UIControlStateNormal)];
                [_addClassBtn setTitle:@"已加入" forState:(UIControlStateSelected)];
                _addClassBtn.clipsToBounds = YES;
                _addClassBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
                _addClassBtn.spacingBetweenImageAndTitle = 7;
                _addClassBtn.titleLabel.font = WGSystem14Font;
        }
        return _addClassBtn;
}
- (QMUIButton *)completeClassBtn
{
        if ( _completeClassBtn == nil )
        {
                _completeClassBtn = [[QMUIButton alloc] qmui_initWithImage:[UIImage wan_cheng_gai_shi_pin_xue_xi] title:@"完成该视频学习"];
                [_completeClassBtn setTitle:@"取消完成视频学习" forState:(UIControlStateSelected)];
                [_completeClassBtn setTitleColor:UIColorHex(0x333333) forState:(UIControlStateNormal)];
                _completeClassBtn.clipsToBounds = YES;
                _completeClassBtn.spacingBetweenImageAndTitle = 7;
                _completeClassBtn.imageView.contentMode = UIViewContentModeScaleAspectFit;
                _completeClassBtn.titleLabel.font = WGSystem14Font;
        }
        return _completeClassBtn;
}
@end
